﻿using Assets.Script.HelpSystem.AtkSystem;
using UnityEngine;

namespace Assets.Script.Human.Player
{
    public class NetPlayerController:MonoBehaviour
    {

        private PlayerActionManager actionManager;
        private PlayerBody playerBody;
        private AtkManager atkManager;
        private bool isLocalPlayer;
        
        #region 网络平滑数据 NetSmoothData
        Vector3 turePos;
        #endregion

        private void Awake()
        {
            turePos = transform.position;
        }

        public void Init(PlayerActionManager actionManager, PlayerBody playerBody, AtkManager atkManager, bool isLoalPlayer)
        {
            actionManager.Init(playerBody);
            this.actionManager = actionManager;
            this.playerBody = playerBody;
            this.atkManager = atkManager;
            this.isLocalPlayer = isLoalPlayer;
        }

        public void UpdatePos(Vector3 newPos)
        {
            turePos = newPos;
        }


        public void PlayerAtkStart(int killIndex)
        {
            atkManager.AttackStart(killIndex);
        }
        public void PlayerAtkEnd()
        {
            atkManager.AttackEnd();
        }

        public void Update()
        {
            atkManager.Update();
            NetSmooth();
        }

        private void NetSmooth()
        {
            if (isLocalPlayer) return;
            var v3 = Vector3.MoveTowards(transform.position, turePos, playerBody.PlayerData.RunSpeed*Time.deltaTime);
            transform.position = v3;
        }

        public void ChangePlayerHp(float hp)
        {
            playerBody.SetHp(hp);
        }
        public void ChangePlayerMp(float mp)
        {
            playerBody.GetMana(mp);
        }
    }
}